package main

import (
	"fmt"
	"os"
	"strings"
	"time"
)

func wout(format string, args ...any) {
	fmt.Print("+++ ", time.Now().Format("2006-01-02 15:04:05.000 "))
	fmt.Printf(format, args...)
	fmt.Println()
}

func werr(err error, format string, args ...any) {
	fmt.Fprint(os.Stderr, "+++ ", time.Now().Format("2006-01-02 15:04:05.000 "))
	fmt.Fprint(os.Stderr, format, args)
	fmt.Fprintf(os.Stderr, " Error: %v\n", err)
	fmt.Fprintln(os.Stderr)
	os.Exit(1)
}

func wsep(title string) {
	width := 60
	padding := "-"
	if title == "" {
		fmt.Println(strings.Repeat(padding, width))
		return
	}
	title = strings.TrimSpace(title)
	tsize := len(title)
	left := (width-tsize)/2 - 1
	right := width - tsize - left - 2
	if left < 0 {
		left = 0
	}
	if right < 0 {
		right = 0
	}
	fmt.Printf("%s %s %s\n", strings.Repeat(padding, left), title, strings.Repeat(padding, right))
}

func usage() {
	fmt.Fprintf(os.Stderr, "Usage: %s url [tcp-addr]\n", os.Args[0])
	os.Exit(1)
}
